/**
 * @author: Miss.杨
 * @date: 2025年3月08日 17:37:06
 * @description: 
 */
package com.sheepone.monitor.audit.server;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

import com.sheepone.monitor.audit.core.entities.ModuleSelectableInfo;

/**
 * @author: Miss.杨
 * @date: 2025年3月08日 17:37:06
 * @description:
 */
public class ModuleRouter {
    private final HashMap<String, ActionRouter> actionRouters = new HashMap<>();
    private final HashMap<String, String> moduleConfigNameMapping = new HashMap<>();

    public ActionRouter route(String action) {
        return actionRouters.get(action);
    }

    public void register(String module, String configNameMapping, ActionRouter router) {
        actionRouters.put(module, router);
        moduleConfigNameMapping.put(module, configNameMapping);
    }

    public List<ModuleSelectableInfo> getModuleSelectableList() {
        ArrayList<ModuleSelectableInfo> list = new ArrayList<>(actionRouters.size());
        for (Entry<String, ActionRouter> entry : actionRouters.entrySet()) {
            String module = entry.getKey();
            ActionRouter router = entry.getValue();
            ModuleSelectableInfo info = new ModuleSelectableInfo();
            String name = moduleConfigNameMapping.get(module);
            info.setName(name == null ? module : module);
            info.setValue(module);
            info.setAction(router.getActionSelectableList());
            list.add(info);
        }
        return list;
    }

}
